home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / mhs_c.arc / OUTPOST.ARC / OUTPOST.C < prev    next >
C/C++ Source or Header  |  1988-06-27  |  5KB  |  207 lines

  1. /* (C) Copyright 1987,1988 - TaxWare/Neil W. Taylor */
  2.  
  3. #include "cctypes.h"
  4. /* #define WORKSPACE 2000 */
  5.  
  6. /* ****************** GLOBAL VARIABLES ****************** */
  7.  
  8. int ErrorsInThisFile = 0;
  9. int WarningsInThisFile = 0;
  10. int warningFound;
  11. int contentsWritten = 0;
  12. int comType;
  13.  
  14. int InFile;
  15. int OutFile;
  16. char InFileName[256];
  17. char OutFileName[256];
  18. char workArea[64]; /* argv[4] */
  19. char messageBuffer[MESSAGE_SIZE];
  20. FILEINFO fileInfo;
  21.  
  22. XRB XRBRec[24];
  23.  
  24. int lineNumber = 0, lNumber = 0;
  25.  
  26. /* char Out[WORKSPACE]; */
  27. /* char originatingHost[37]; */
  28. long fileSize = 0;
  29.  
  30. char InExtension[] = ".XRB";
  31. char OutExtension[] = ".CCM";
  32.  
  33. char *CommandTypes[] = {
  34.     "",
  35.     "Date:",
  36.     "From:",
  37.     "To:",
  38.     "Message-id:",
  39.     "Conversation-id:",
  40.     "Via-host:",
  41.     "Subject:",
  42.     "Message-type:",
  43.     "Copies-to:",
  44.     "Re-sent-by:",
  45.     "Respond-by:",
  46.     "Possibility:",
  47.     "Action:",
  48.     "Ret-Message:",
  49.     "In-reply-to:",
  50.     "Form:",
  51.     "Domain:",
  52.     "Complete-by:",
  53.     "New-complete-by:",
  54.     "Attachment-name:",
  55.     "Net-attachment:",
  56.     0
  57. };
  58.  
  59. char *ErrorTypes[] = {
  60.     "Unknown Error",
  61.     "Syntax",
  62.     "Cannot Open File",
  63.     "Cannot Create Output",
  64. };
  65.  
  66. void    UpperCase();
  67. int        Parse();
  68. extern int        OpenInputFile();
  69. extern int        OpenOutputFile();
  70. int        GetCommandType();
  71. int        GetParameter();
  72. int        SetUpOutFile();
  73. void    FinishUpOutFile();
  74. void    Error();
  75. void    Warning();
  76. int        MergeIt();
  77. /* void    InitMCB(); */
  78.  
  79. /* extern int FindFirstFile();
  80. extern int FindNextFile(); */
  81.  
  82. void WriteLine();
  83.  
  84. void main(argc, argv)
  85. int argc;
  86. char *argv[];
  87. {
  88.     int exitCode = ERROR_ENCOUNTERED, ccode, pause = 0, totalMsgs = 0, i;
  89.     char commandLine[256], command[80], *p, searchAttributes;
  90.  
  91.     system("CLS");
  92.     for ( i = 1; i < 6; i++ )
  93.         WriteLine("\0");
  94.  
  95.     WriteLine("   MHS / cc:Mail Gateway\0");
  96.     WriteLine("\0");
  97.     WriteLine("   Converting message(s) to cc: format...\0");
  98.     WriteLine("\0");
  99.  
  100.     if (argc != 7 ) goto Out;
  101.  
  102.     /* *************** OUTPOST ALGORITHM **************** */
  103.  
  104.     /* MAP Q: to argv[5] (gateway host area) */
  105.     /* MAP P: to argv[4] (gateway host mailbag/database area) */
  106.  
  107.     /*  FindFirstFile(filePath, fileInfo, searchAttributes); */
  108. Repeat:
  109.     /* get next SMF file from Q:OUT (and open for reading, if parsing */
  110.     /* directly to CC:MAIL format) */
  111.     /* (if the SMF file got this far, we know that it is destined for CC:MAIL */
  112.     /* XRBOXOUT the current SMF file to a temp file .XRB in the host's */
  113.     /* mail area (P:) */
  114.     /* convert the .XRB file to CC:MAIL format and... */
  115.     /* IMPORT that file into CC:MAIL's database */
  116.     /* if the IMPORT is successful, unlink the $T file (what about any attachments ?) */
  117.     /*     FindNextFile(fileInfo); */
  118.     /* goto Repeat */
  119.  
  120.     strcpy(workArea, argv[4]);
  121.  
  122.     sprintf(commandLine, "MAP Q:=%s > NUL:", argv[5]);
  123.     system(commandLine);
  124.  
  125.     sprintf(commandLine, "MAP P:=%s > NUL:", workArea);
  126.     system(commandLine);
  127.  
  128.     searchAttributes = (char)0;
  129.     /* filename is $T*. under NetWare and *. under DOS */
  130.  
  131.     sprintf(command, "Q:OUT\\*.");
  132.     ccode = FindFirstFile(command, &fileInfo, searchAttributes);
  133.  
  134.     while ( !ccode ) {
  135.  
  136.         messageBuffer[0] = '\0';
  137.         contentsWritten = 0;
  138.  
  139.         /* *******XRBOXOUT********* */
  140.         sprintf(commandLine, "XRBOXOUT Q:OUT\\%s >P:CCMAIL.XRB", fileInfo.fileName);
  141.         ccode = system(commandLine);
  142.         if ( ccode ) continue;
  143.  
  144.         /* ******* Get Ready To Read The Newly Created .XRB File */
  145.         sprintf(InFileName, "P:CCMAIL.XRB");
  146.         ccode = OpenInputFile();
  147.         if ( ccode ) {
  148.             Error(CANNOT_OPEN_FILE);
  149.             goto Out;
  150.         }
  151.  
  152.         /* ********* SETUP .CCM FILE ******** */
  153.         if ( SetUpOutFile() ) {
  154.             Error(CANNOT_CREATE_OUTPUT);
  155.             goto Out;
  156.         }
  157.  
  158.         /* ******* PARSE ******* */
  159.         /* PARSE the temporary file created by the XRBOXOUT utility */
  160.         ccode = Parse();
  161.  
  162.         ccode = WriteCCMFileMsg();
  163.  
  164.         /* exec CC:MAIL's IMPORT utility */
  165.         if ( !pause ) {
  166.             WriteLine("\0");
  167.             WriteLine("    Importing message(s) to cc:Mail...\0");
  168.             pause++;
  169.         }
  170.  
  171.         sprintf(commandLine,"IMPORT %s %s P: @P:CCMAIL.CCM >NUL:",argv[1],argv[3]);
  172.         ccode = system(commandLine);
  173.         if ( !ccode ) {
  174.             /* delete the SMF and temp files */
  175.             totalMsgs++;
  176.             unlink("P:CCMAIL.XRB");
  177.             sprintf(command, "Q:OUT\\%s", fileInfo.fileName);
  178.             unlink(command);
  179.             /* ...what about attachment files ??? STUB */
  180.         }
  181.  
  182.         exitCode = NO_ERROR; /* ?? */
  183.         ccode = FindNextFile(&fileInfo);
  184.  
  185.     } /* end while */
  186.     sprintf(command, "   %d message(s) imported.", totalMsgs);
  187.     WriteLine(command);
  188.     WriteLine("\0");
  189.  
  190. Out:
  191.     close(InFile);
  192.     system("CLS");
  193.     exit(exitCode);
  194. }
  195.  
  196. void WriteLine(string)
  197. char *string;
  198. {
  199. /*     char line[80], temp[79];
  200.  
  201.     strncpy(temp, "                                                                      ",
  202.             76-strlen(string));
  203.     sprintf(line, "│%s%s\n", string, temp);
  204.     printf(line); */
  205.     printf("%s\n",string);
  206. }
  207.